// 导入react
import React from 'react';
// 导入组件
import Lists from '@/components/Lists';
import Detail from '@/components/Detail';

// 导入路由组件
import { Switch,Route,Redirect } from 'react-router-dom';


const  routes=[
    {
        path:'/',
        to:'/lists',
        exact:true
    },
    {
        path:'/lists',
        component:Lists,
        exact:false
    },
    {
        path:'/detail/:id',
        component:Detail,
        exact:false
    }
];

function router(){
    return <Switch>
                {routes.map((item,index)=>(
                <Route key={index}  exact={item.exact} path={item.path} render={(routeProps)=>{
                    if(item.component){
                        return <item.component {...routeProps} />
                    }else{
                        return <Redirect to={{pathname:item.to}}/>
                    }
                }} />
            ))}
        </Switch>
}
export default router;